package com.tiancheng.trade.merchant.controller.admin;


import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.web.http.PlatformRequest;
import com.tiancheng.trade.merchant.configuration.YnTourProperties;
import com.tiancheng.trade.merchant.util.DictUtil;
import com.tiancheng.trade.merchant.vo.KeyValueVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/property")
public class PropertyController {
    @Autowired
    private YnTourProperties ynTourProperties;
    @Resource
    private PlatformRequest platformRequest;

    @GetMapping(value = "/dictionary")
    public Result<?> getDict(@RequestParam(name = "type", required = false) String type) {
        if (StringUtils.isBlank(type)) {
            Map<String, List<KeyValueVO>> all = DictUtil.getDict();
            return Result.success(all);
        }
        return Result.success(DictUtil.getDict(type));

    }

    /**
     * 城市行政编码接口
     *
     * @param pid  上级行政机构的id，比如昆明385
     * @param type 2：州/市，3：区县
     * @return {@link Result}
     */
    @GetMapping(value = "/region")
    public Result<?> getRegion(@RequestParam(required = false) String pid, @RequestParam(required = false) String type) {
        HashMap<String, Object> map = new HashMap<>();
        if (StringUtils.isNotBlank(pid)) {
            map.put("pid.value", pid);
        }
        if (StringUtils.isBlank(type)) {
            type = "2";
        }
        map.put("type.value", type);
        return platformRequest.getRequest(ynTourProperties.getQueryCityUrl(), map);
    }
}
